package com.fz.controller;

import com.fz.entity.TopicComment;
import com.fz.service.TopicCommentService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 存储话题评论信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/topicComment")
public class TopicCommentController {
    @Resource
   TopicCommentService topicCommentService;



    // 获取话题下的评论列表
    @GetMapping("/list")
    public List<TopicComment> getCommentsByTopic(Long topicId) {
        return topicCommentService.getCommentsByTopicId(topicId);
    }

    // 发表评论
    @PostMapping("/add")
    public ResultVo<TopicComment> createComment(Long topicId,Long userId,String content) {
        TopicComment topicComment=topicCommentService.createComment(topicId,userId,content);
        return ResultVo.success(topicComment ,"评论成功");
    }

    // 评论点赞
    @PostMapping("/like")
//    public ResultVo<Void> likeComment(@PathVariable Long id) {
    public Boolean likeComment(Long id) {
        return topicCommentService.likeComment(id);
//        return ResultVo.success(topicCommentService.likeComment(id));
    }

    // 删除评论（逻辑删除）
    @DeleteMapping("/del")
    public Boolean deleteComment(Long id) {
        TopicComment comment = new TopicComment();
        comment.setIsDeleted(1);
        return topicCommentService.updateById(comment);
    }
}
